package com.github.rxyor.example.spring.transaction.airplane.service;

import com.github.rxyor.example.spring.transaction.airplane.entity.AirplaneDO;
import com.github.rxyor.example.spring.transaction.airplane.mapper.AirplaneMapper;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

/**
 *<p>
 *
 *</p>
 *
 * @author liuyang
 * @date 2019/9/17 周二 17:48:00
 * @since 1.0.0
 */
@Slf4j
@AllArgsConstructor
@Repository("airplaneRepo")
public class AirplaneRepoImpl implements AirplaneRepo {

    private final AirplaneMapper airplaneMapper;

    /**
     *保存
     *
     * @author liuyang
     * @date 2019-09-17 周二 17:47:56
     * @param entity entity
     * @return
     */
    @Transactional
    @Override
    public void save(AirplaneDO entity) {
        if (entity == null) {
            throw new IllegalArgumentException("save airplane param can't be null");
        }
        int affectRows = airplaneMapper.insert(entity);
        if (affectRows != 1) {
            throw new RuntimeException("save airplane fail, unexpected affect rows");
        }
    }
}
